home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Util / CnvConfig / CnvConfig.c next >
Encoding:
C/C++ Source or Header  |  1994-12-22  |  8.3 KB  |  350 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     CnvConfig.c
  5.  
  6.     DESCRIPTION
  7.     Converts an old config-file into the actual version or prints an
  8.     old version-file to stdout.
  9.  
  10.     NOTES
  11.  
  12.     BUGS
  13.  
  14.     TODO
  15.  
  16.     EXAMPLES
  17.  
  18.     SEE ALSO
  19.  
  20.     INDEX
  21.  
  22.     HISTORY
  23.     30. Mar 1993    ada created
  24.  
  25. ******************************************************************************/
  26.  
  27. /**************************************
  28.         Includes
  29. **************************************/
  30. #include <exec/types.h>
  31. #include <exec/nodes.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <pragmas/dos_pragmas.h>
  36.  
  37. #ifndef DOS_DOS_H
  38. typedef void * BPTR;
  39. #endif
  40. /* typedef struct Node NODE; */
  41.  
  42. #include "global.h"
  43.  
  44.  
  45. /**************************************
  46.         Globale Variable
  47. **************************************/
  48. extern struct DOSBase * DOSBase;
  49.  
  50.  
  51. /**************************************
  52.       Interne Defines & Strukturen
  53. **************************************/
  54.  
  55.  
  56. /**************************************
  57.         Interne Variable
  58. **************************************/
  59.  
  60.  
  61. /**************************************
  62.        Interne Prototypes
  63. **************************************/
  64. void convert_config0001 (void);
  65. void convert_config0002 (void);
  66. void convert_config0003 (void);
  67. void print_config (void);
  68.  
  69.  
  70. struct Config new;
  71. struct Config0001 c1;
  72. struct Config0002 c2;
  73. struct Config0003 c3;
  74.  
  75.  
  76. void convert_config0001 (void)
  77. {
  78.     new.wwcol = c1.wwcol;
  79.     new.winx = c1.winx;
  80.     new.winy = c1.winy;
  81.     new.winwidth = c1.winwidth;
  82.     new.winheight = c1.winheight;
  83.     new.iwinx = c1.iwinx;
  84.     new.iwiny = c1.iwiny;
  85.     new.aslleft = c1.aslleft;
  86.     new.asltop = c1.asltop;
  87.     new.aslwidth = c1.aslwidth;
  88.     new.aslheight = c1.aslheight;
  89.     new.tabstop = c1.tabstop;
  90.     new.margin = c1.margin;
  91.     new.fgpen = c1.fgpen;
  92.     new.bgpen = c1.bgpen;
  93.     new.hgpen = c1.hgpen;
  94.     new.bbpen = c1.bbpen;
  95.     new.tfpen = c3.fgpen;
  96.     new.tbpen = c3.tpen;
  97.     new._insertmode = c1.insertmode;
  98.     new._ignorecase = c1.ignorecase;
  99.     new._wordwrap = c1.wordwrap;
  100.     new._autosplit = c1.autosplit;
  101.     new._autoindent = c1.autoindent;
  102.     new._autounblock = c1.autounblock;
  103. } /* convert_config0001 */
  104.  
  105.  
  106. void convert_config0002 (void)
  107. {
  108.     new.wwcol = c2.wwcol;
  109.     new.winx = c2.winx;
  110.     new.winy = c2.winy;
  111.     new.winwidth = c2.winwidth;
  112.     new.winheight = c2.winheight;
  113.     new.iwinx = c2.iwinx;
  114.     new.iwiny = c2.iwiny;
  115.     new.aslleft = c2.aslleft;
  116.     new.asltop = c2.asltop;
  117.     new.aslwidth = c2.aslwidth;
  118.     new.aslheight = c2.aslheight;
  119.     new.tabstop = c2.tabstop;
  120.     new.margin = c2.margin;
  121.     new.fgpen = c2.fgpen;
  122.     new.bgpen = c2.bgpen;
  123.     new.hgpen = c2.hgpen;
  124.     new.bbpen = c2.bbpen;
  125.     new.tfpen = c3.fgpen;
  126.     new.tbpen = c3.tpen;
  127.     new._insertmode = c2.insertmode;
  128.     new._ignorecase = c2.ignorecase;
  129.     new._wordwrap = c2.wordwrap;
  130.     new._autosplit = c2.autosplit;
  131.     new._autoindent = c2.autoindent;
  132.     new._autounblock = c2.autounblock;
  133. } /* convert_config0002 */
  134.  
  135.  
  136. void convert_config0003 (void)
  137. {
  138.     new.wwcol = c3.wwcol;
  139.     new.winx = c3.winx;
  140.     new.winy = c3.winy;
  141.     new.winwidth = c3.winwidth;
  142.     new.winheight = c3.winheight;
  143.     new.iwinx = c3.iwinx;
  144.     new.iwiny = c3.iwiny;
  145.     new.aslleft = c3.aslleft;
  146.     new.asltop = c3.asltop;
  147.     new.aslwidth = c3.aslwidth;
  148.     new.aslheight = c3.aslheight;
  149.     new.tabstop = c3.tabstop;
  150.     new.margin = c3.margin;
  151.     new.fgpen = c3.fgpen;
  152.     new.bgpen = c3.bgpen;
  153.     new.hgpen = c3.hgpen;
  154.     new.bbpen = c3.bbpen;
  155.     new.tfpen = c3.fgpen;
  156.     new.tbpen = c3.tpen;
  157.     new._insertmode = c3.insertmode;
  158.     new._ignorecase = c3.ignorecase;
  159.     new._wordwrap = c3.wordwrap;
  160.     new._autosplit = c3.autosplit;
  161.     new._autoindent = c3.autoindent;
  162.     new._autounblock = c3.autounblock;
  163. } /* convert_config0003 */
  164.  
  165.  
  166. void print_config (void)
  167. {
  168.     printf ("wwcol %d\n", new.wwcol);
  169.     printf ("setgeometry %d %d %d %d\n",
  170.         new.winx, new.winy, new.winwidth, new.winheight);
  171.     printf ("# iconpos %d %d\n", new.iwinx, new.iwiny);
  172.     printf ("# aslgeometry %d %d %d %d\n",
  173.         new.aslleft, new.asltop, new.aslwidth, new.aslheight);
  174.     printf ("tabstop %d\n", new.tabstop);
  175.     printf ("margin %d\n", new.margin);
  176.     printf ("fgpen %d\n", new.fgpen);
  177.     printf ("bgpen %d\n", new.bgpen);
  178.     printf ("hgpen %d\n", new.hgpen);
  179.     printf ("bbpen %d\n", new.bbpen);
  180.     printf ("tfpen %d\n", new.tfpen);
  181.     printf ("tbpen %d\n", new.tbpen);
  182.  
  183.     printf ("insertmode %s\n", new._insertmode ? "on" : "off");
  184.     printf ("ignorecase %s\n", new._ignorecase ? "on" : "off");
  185.     printf ("wordwrap %s\n", new._wordwrap ? "on" : "off");
  186.     printf ("autosplit %s\n", new._autosplit ? "on" : "off");
  187.     printf ("autoindent %s\n", new._autoindent ? "on" : "off");
  188.     printf ("autounblock %s\n", new._autounblock ? "on" : "off");
  189.     printf ("doback %s\n", new._doback ? "on" : "off");
  190.     printf ("nicepaging %s\n", new._nicepaging ? "on" : "off");
  191.     printf ("iconactive %s\n", new._iconactive ? "on" : "off");
  192.     printf ("blockendsfloat %s\n", new._blockendsfloat ? "on" : "off");
  193. } /* print_config */
  194.  
  195.  
  196. void main (int argc, char ** argv)
  197. {
  198.     FILE * fh;
  199.     char tmp_buffer[256];
  200.     int out = 0;
  201.     char * outfile = XDME_CONFIG;
  202.     int current = FALSE;
  203.  
  204.     if (argc == 2 && argv[1][0] == '?')
  205.     {
  206. usage:
  207.     puts ("CnvConfig converts old config-files\n"
  208.           "Usage : CnvConfig [-p] [-o <file>]\n\n"
  209.           "Without arguments it asks whether to write the new config\n"
  210.           "back or prints it on stdout.\n"
  211.           "You can specify either -p or -o. -p prints the old config\n"
  212.           "to stdout. You can redirect this into a file and let XDME\n"
  213.           "source this file. Or -o <file> writes the new config to\n"
  214.           "<file>.");
  215.     exit (0);
  216.     }
  217.     else if (argc > 1 && argv[1][0] == '-')
  218.     {
  219.     if (argv[1][1] == 'p')
  220.         out = 2;
  221.     else if (argv[1][1] == 'o')
  222.     {
  223.         if (argv[1][2])
  224.         outfile = &argv[1][2];
  225.         else
  226.         {
  227.         if (argc != 3)
  228.             goto usage;
  229.  
  230.         outfile = argv[2];
  231.         }
  232.  
  233.         out = 1;
  234.     }
  235.     else
  236.         goto usage;
  237.     }
  238.  
  239.     if (fh = fopen (XDME_CONFIG, "r"))
  240.     {
  241.     fread (tmp_buffer, sizeof(CONFIG_VERSION)-1, 1, fh);
  242.  
  243.     if (!strncmp (CONFIG0001, tmp_buffer, sizeof(CONFIG0001)-1) )
  244.     {
  245.         printf ("# Found config \"" CONFIG0001 "\" ...\n");
  246.  
  247.         fgetc (fh);
  248.         memset (&c1, 0, CONFIG0001_SIZE);
  249.         fread (&c1, 1, CONFIG0001_SIZE, fh);
  250.  
  251.         convert_config0001 ();
  252.     }
  253.     else if (!strncmp (CONFIG0002, tmp_buffer, sizeof(CONFIG0002)-1) )
  254.     {
  255.         printf ("# Found config \"" CONFIG0002 "\" ...\n");
  256.  
  257.         fgetc (fh);
  258.         memset (&c2, 0, CONFIG0002_SIZE);
  259.         fread (&c2, 1, CONFIG0002_SIZE, fh);
  260.  
  261.         convert_config0002 ();
  262.     }
  263.     else if (!strncmp (CONFIG0003, tmp_buffer, sizeof(CONFIG0003)-1) )
  264.     {
  265.         printf ("# Found config \"" CONFIG0003 "\" ...\n");
  266.  
  267.         memset (&c3, 0, CONFIG0003_SIZE);
  268.         fread (&c3, 1, CONFIG0003_SIZE, fh);
  269.  
  270.         convert_config0003 ();
  271.     }
  272.     else if (!strncmp (CONFIG_VERSION, tmp_buffer, sizeof(CONFIG0004)-1) )
  273.     {
  274.         current = TRUE;
  275.  
  276.         printf ("# Found current config ...\n");
  277.  
  278.         fread (&new, 1, CONFIG_SIZE, fh);
  279.     }
  280.     else
  281.     {
  282.         tmp_buffer[sizeof(CONFIG_VERSION)] = 0;
  283.  
  284.         printf ("Unknown config-file \"%s\"\n", tmp_buffer);
  285.         exit (5);
  286.     }
  287.  
  288.     fclose (fh);
  289.  
  290.     if (!out)
  291.     {
  292.         printf ("Do you want\n%s"
  293.         "\t(2) print config to stdout\n"
  294.         "\t(3) exit without doing anything\n"
  295.         ":",
  296.         current ? "" : "\t(1) convert \"" XDME_CONFIG "\" to \"" CONFIG_VERSION "\" \n"
  297.         );
  298.  
  299.         gets (tmp_buffer);
  300.         out = atoi (tmp_buffer);
  301.     }
  302.  
  303.     switch (out)
  304.     {
  305.     case 1:
  306.         if (current)
  307.         {
  308.         printf ("\"" XDME_CONFIG "\" is uptodate.\n");
  309.         break;
  310.         }
  311.  
  312.         printf ("Copying \"" XDME_CONFIG "\" to \"" XDME_CONFIG ".bak\"\n");
  313.         DeleteFile (XDME_CONFIG ".bak");
  314.         Rename (XDME_CONFIG, XDME_CONFIG ".bak");
  315.  
  316.         if (fh = fopen (outfile, "w"))
  317.         {
  318.         printf ("Writing new config-file.\n");
  319.         fwrite (CONFIG_VERSION, sizeof(CONFIG_VERSION)-1, 1, fh);
  320.         fwrite (&new, CONFIG_SIZE, 1, fh);
  321.         fclose (fh);
  322.         }
  323.         else
  324.         {
  325.         printf ("Cannot open \"%s\" for writing.\n"
  326.             "copying \"" XDME_CONFIG ".bak\" back\n" , outfile);
  327.         Rename (XDME_CONFIG ".bak", XDME_CONFIG);
  328.         exit (10);
  329.         }
  330.  
  331.         break;
  332.  
  333.     case 2:
  334.         print_config ();
  335.     }
  336.     }
  337.     else
  338.     {
  339.     printf ("Cannot open \"" XDME_CONFIG "\" for reading.\n");
  340.     exit (10);
  341.     }
  342.  
  343.     exit (0);
  344. }
  345.  
  346.  
  347. /******************************************************************************
  348. *****  ENDE CnvConfig.c
  349. ******************************************************************************/
  350.